package com.wangce.controller;

import com.wangce.entity.User;
import com.wangce.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * ClassName: LoginController
 * Description:
 * date: 2021/11/22 10:26
 *
 * @author 凡人
 * @since JDK 1.8
 */
@Controller
public class LoginController {

    @Autowired
    LoginService service;

    @RequestMapping("toLogin")
    public String toLogin(){
        return "login";
    }

    /**
     * 登陆
     * @param session
     * @param u
     * @return
     */
    @RequestMapping("login")
    public String login(HttpSession session,User u){
        User user = service.login(u);
        if(user != null){
            session.setAttribute("user",user);
            return "redirect:index";
        }
        return "login";
    }
}
